package org.abacus.platform.data;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class FetchDatabase implements Store {
	private Store store;
	private ConnectionProvider connectionProvider;
	private Connection conn;

	public FetchDatabase(ConnectionProvider connectionProvider, String sql) {
		super();
		this.connectionProvider = connectionProvider;
		try {
			conn = connectionProvider.getConnection();
			store = new FetchStatement(conn.createStatement(), sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void open() {
		store.open();
	}

	@Override
	public List<Map<String, Object>> getStore() {
		return store.getStore();
	}

	@Override
	public List<Key> getKeys() {
		return store.getKeys();
	}

	@Override
	public void close() {
		store.close();
		connectionProvider.close(conn);
	}

}
